package com.gblfy.httpclinet.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ThirdPartyController {

    /**
     * 模拟第三方厂商
     *
     * @param paramRequest
     * @return
     */
    @GetMapping(value = "/get/noParams2/*", produces = "application/json;charset=UTF-8")
    public String receiveHttpClientGet(HttpServletRequest paramRequest) {
        String token = paramRequest.getParameter("token");
        String batch_no = paramRequest.getParameter("batch_no");
        System.out.println("接收到的鉴权token: " + token + " ,接收到的批处理编码: " + batch_no);
        return "接收到的鉴权token: " + token + " ,接收到的批处理编码: " + batch_no;
    }

    /**
     * 第三方处理post请求json（入参）
     * 案例:http://localhost:8080/get/noParams/zbx?token=123&batch_no=567
     *
     * @param paramRequest
     * @return
     */
    @PostMapping(value = "/post/josn/Params2/*", produces = "application/json;charset=UTF-8")
    public String receiveHttpClientPostToHttp(HttpServletRequest paramRequest, @RequestBody String requestBody) {
        return "第三方厂商报文：" + requestBody;
    }
}
